﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTSandInspectionService : ServiceHandle, IRPTSandInspection 
    {
        #region IRPTSandInspection Members

        public OperationResult<List<tb_RPT_SandInspection>> GetAllSandInspection()
        {
            OperationResult<List<tb_RPT_SandInspection>> result = new OperationResult<List<tb_RPT_SandInspection>>();
            List<tb_RPT_SandInspection> list = new List<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllSandInspection();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SandInspection>> GetSandInspectionBySequence(string strSequence)
        {
            OperationResult<List<tb_RPT_SandInspection>> result = new OperationResult<List<tb_RPT_SandInspection>>();
            List<tb_RPT_SandInspection> list = new List<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSandInspectionBySequence(strSequence);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SandInspection>> GetSandInspectionByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_SandInspection>> result = new OperationResult<List<tb_RPT_SandInspection>>();
            List<tb_RPT_SandInspection> list = new List<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSandInspectionByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SandInspection>> GetSandInspectionByContition(string strSequence, string strProjectName, string strMaterial, string strTestDate)
        {
            OperationResult<List<tb_RPT_SandInspection>> result = new OperationResult<List<tb_RPT_SandInspection>>();
            List<tb_RPT_SandInspection> list = new List<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSandInspectionByContition(strSequence, strProjectName, strMaterial, strTestDate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SandInspection> GetSandInspectionById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_SandInspection> result = new OperationResult<tb_RPT_SandInspection>();
            tb_RPT_SandInspection sandInspection;
            try
            {
                sandInspection = dataContext.GetSandInspectionById(id);
                if (sandInspection == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = sandInspection;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SandInspection> CreateSandInspection(tb_RPT_SandInspection entity)
        {
            OperationResult<tb_RPT_SandInspection> result = new OperationResult<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateSandInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SandInspection> ModifySandInspection(tb_RPT_SandInspection entity)
        {
            OperationResult<tb_RPT_SandInspection> result = new OperationResult<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifySandInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SandInspection> DeleteSandInspection(tb_RPT_SandInspection entity)
        {
            OperationResult<tb_RPT_SandInspection> result = new OperationResult<tb_RPT_SandInspection>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteSandInspection(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
